home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 015a / bootwhat.zip / S_ESIX.C < prev    next >
C/C++ Source or Header  |  1990-12-17  |  3KB  |  126 lines

  1. /* This file contains system-specific functions for ESIX.
  2.  * The program pfdisk.c calls these routines.
  3.  * Note that ESIX can't use the generic Sys.V/386 version of
  4.  * this file because it uses ioctl calls to access the
  5.  * primary boot sector.  Other systems provide a device which
  6.  * maps onto the whole disk (starting with the boot sector).
  7.  */
  8. #include <stdio.h>
  9. #include <fcntl.h>
  10. #include <sys/types.h>
  11. #include <sys/vtoc.h>
  12.  
  13. #define extern
  14. #include "sysdep.h"
  15. #undef extern
  16.  
  17. int usage(prog)    /* print a usage message */
  18. char    *prog;    /* program name */
  19. {
  20.   fprintf(stderr,"Usage: %s dev\n\t%s\n", prog,
  21.       "where 'dev' is the device name, i.e. /dev/rdsk/0s0");
  22. }
  23.  
  24. void getGeometry(dev, c, h, s)
  25. char    *dev;        /* device name */
  26. unsigned *c,*h,*s;    /* cyls, heads, sectors */
  27. {
  28.   int devfd, retval;
  29.   struct disk_parms dp;
  30.   
  31.   devfd = open(dev, O_RDONLY, 0);
  32.   if (devfd < 0) {
  33.     fprintf(stderr,"%s: can't open for reading\n", dev);
  34.     return;
  35.   }
  36.   retval = ioctl(devfd, V_GETPARMS, &dp);
  37.   close(devfd);
  38.   if (retval < 0) {
  39.     fprintf(stderr,"%s: can't get disk parameters\n", dev);
  40.     return;
  41.   }
  42.   if (dp.dp_type != DPT_WINI) {
  43.     fprintf(stderr,"%s: not a Winchester Disk\n", dev);
  44.     return;
  45.   }
  46.   *c = dp.dp_cyls;
  47.   *h = dp.dp_heads;
  48.   *s = dp.dp_sectors;
  49. }
  50.  
  51. int getFile(name, buf, len)    /* read file into buffer */
  52. char    *name, *buf;
  53. int    len;
  54. {    /* (open, read, close) */
  55.   int devfd, retval;
  56.   
  57.   devfd = open(name, O_RDONLY, 0);
  58.   if (devfd < 0) {
  59.     fprintf(stderr,"%s: can't open for reading\n", name);
  60.     return(devfd);
  61.   }
  62.   retval = read(devfd, buf, len);
  63.   if (retval < 0)
  64.     fprintf(stderr,"%s: read failed\n", name);
  65.   close(devfd);
  66.   return(retval);
  67. }
  68.  
  69. int putFile(name, buf, len)    /* write buffer to file */
  70. char    *name, *buf;
  71. int    len;
  72. {    /* (open, write, close) */
  73.   int devfd, retval;
  74.   
  75.   devfd = open(name, O_WRONLY|O_CREAT, 0666);
  76.   if (devfd < 0) {
  77.     fprintf(stderr,"%s: can't open for writing\n", name);
  78.     return(devfd);
  79.   }
  80.   retval = write(devfd, buf, len);
  81.   if (retval < 0)
  82.     fprintf(stderr,"%s: write failed\n", name);
  83.   close(devfd);
  84.   return(retval);
  85. }
  86.  
  87. int getBBlk(name, buf)    /* read Boot Block into buffer */
  88. char    *name, *buf;
  89. {    /* (open, read, close) */
  90.   int devfd, retval;
  91.   struct absio abs;
  92.   
  93.   devfd = open(name, O_RDONLY, 0);
  94.   if (devfd < 0) {
  95.     fprintf(stderr,"%s: can't open for reading\n", name);
  96.     return(devfd);
  97.   }
  98.   abs.abs_sec = 0;    /* the primary boot sector */
  99.   abs.abs_buf = buf;
  100.   retval = ioctl(devfd, V_RDABS, &abs);
  101.   if (retval < 0)
  102.     fprintf(stderr,"%s: read failed\n", name);
  103.   close(devfd);
  104.   return(retval);
  105. }
  106.  
  107. int putBBlk(name, buf)    /* write buffer to Boot Block */
  108. char    *name, *buf;
  109. {    /* (open, write, close) */
  110.   int devfd, retval;
  111.   struct absio abs;
  112.   
  113.   devfd = open(name, O_WRONLY, 0);
  114.   if (devfd < 0) {
  115.     fprintf(stderr,"%s: can't open for writing\n", name);
  116.     return(devfd);
  117.   }
  118.   abs.abs_sec = 0;    /* the primary boot sector */
  119.   abs.abs_buf = buf;
  120.   retval = ioctl(devfd, V_WRABS, &abs);
  121.   if (retval < 0)
  122.     fprintf(stderr,"%s: write failed\n", name);
  123.   close(devfd);
  124.   return(retval);
  125. }
  126.